#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "extern.h"

int
main(int argc, char *argv[]) {
int arg = atoi(argv[2]);
//struct stat st;
//stat(argv[2],&st);
/*
//prueba:TODO:Borrar esta linea

char* charPrueba;
int regular = (atoi(argv[1]) == atoi(argv[2]));
printf ("%d es igual a %d? :%d\n",atoi(argv[1]), atoi(argv[2]), regular);
FILE *fp = fopen(argv[3], "r");
int nbytes = fread (charPrueba, 1, 1 ,fp);
printf ("%d bytes leidos\n", nbytes);
printf ("%c",charPrueba);
*/
int auxChar;
int variable;
int nbytes;
char booleano=0;
FILE *fp = fopen(argv[3], "r");
struct stat sb;
/**
int res = fstat(fileno(fp), &sb);
__off_t resultado = sb.st_size;
printf ("%d",resultado);
*/
//printf("\n");
variable = atoi(argv[1]);
while ((arg-->0 )&& variable++){
	printf("iteracion\n");
}
printf("%d",variable);
/**
while ((auxChar = fgetc(fp)) != EOF){
		//fread (&auxChar, 1, 1, fp) == 1){
	if (auxChar != '\n')
		booleano = 1;
	else booleano = 0;
	
	if (booleano)
		printf("%c",auxChar);
}
/**
int devol = fseek(fp,0,SEEK_END);
devol = ftell(fp);
printf ("%d",devol);
//nbytes = fread(&auxChar,1,1,fp);
char contLineas = 0;
//printf("Dentro del infinito: %d\n",nbytes);
/*
while (arg > 0){
	nbytes = fread(&auxChar,1,1,fp);
	if (auxChar == '\n')
		arg--;
	fseek(fp,-2,SEEK_CUR);
	contLineas++;
	printf("Dentro del infinito: %c\n",auxChar);
}
fseek(fp,3,SEEK_CUR);
	
char* string;
string = malloc(contLineas*sizeof(char));

	/* CODIGO: Mostrar las "off" lineas ultimas
	 * 	y posicionar el puntero de fichero en el ultimo byte mostrado
	 */

/**
while(lect != 0){
		lect = fwrite(fp,1,1,stdout);
	//	printf("%d",lect);
}


	while (arg > 0){
			if  (1 == fread (&auxChar, 1, 1, fp)){
					if (auxChar=='\n')
						arg--;
					
					printf("%c",auxChar);
			}
			else break;
	}

	*/
	return nbytes;
}
//comentario final: Ya esta la v2
